Basic Tree Stats#
Project Description#
In this project, I will be using tree inventory data from Ottawa Open Data to practice data analysis and data visualization work in Python.
Contains information licensed under the Open Government Licence – City of Ottawa
import requests
import pandas as pd
import plotly.express as px
# Eventually add some logic for full data fetching via API, 1000 limit right now
url = "https://maps.ottawa.ca/arcgis/rest/services/Forestry/MapServer/0/query?outFields=*&where=1%3D1&f=geojson"
resp = requests.get(url)
print(resp.status_code)
200
trees = pd.json_normalize(resp.json()['features'])
trees.columns = trees.columns.map(lambda x: x.split(".")[-1])
trees["species_general"] = trees["SPECIES"].str.split(" ").str[0]
trees.head()
| type | id | type | coordinates | OBJECTID | WARD | ADDNUM | ADDSTR | LTLOCATION | RDLOCATION | ... | EDGETREE | PATHTRAIL | SPECIES | DBH | TREATMENT | EABTAGNUMBER | DEDTAGNUMBER | SAP_ID | PROGRAM | species_general | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Feature | 63887 | Point | [-75.6813293769492, 45.431577387384344] | 63887 | 12 | 151 | CHAPEL ST | Front | N/A | ... | 0 | 0 | Linden Littleleaf | 45.0 | None | None | None | 8113295 | None | Linden |
| 1 | Feature | 63888 | Point | [-75.68128713726621, 45.43137388688068] | 63888 | 12 | 151 | CHAPEL ST | Front | N/A | ... | 0 | 0 | Maple Manitoba | 66.0 | None | None | None | 8113293 | None | Maple |
| 2 | Feature | 63889 | Point | [-75.68140123408709, 45.43136945702825] | 63889 | 12 | 151 | CHAPEL ST | Front | N/A | ... | 0 | 0 | Maple Manitoba | 62.0 | None | None | None | 8113292 | None | Maple |
| 3 | Feature | 63890 | Point | [-75.6811069981023, 45.43111744784172] | 63890 | 12 | 153 | CHAPEL ST | Front | N/A | ... | 0 | 0 | Linden Littleleaf | 26.0 | None | None | None | 8113306 | None | Linden |
| 4 | Feature | 63891 | Point | [-75.68098576955637, 45.43104793782418] | 63891 | 12 | 153 | CHAPEL ST | Front | N/A | ... | 0 | 0 | Linden Littleleaf | 31.0 | None | None | None | 8113305 | None | Linden |
5 rows × 21 columns
species_ward_count = pd.DataFrame({'count' : trees.groupby(["species_general", "WARD"])["species_general"].count()}).reset_index()
species_ward_count
fig = px.bar(species_ward_count, x="WARD", y="count", color="species_general", title="Species by Ward")
fig.show()